package com.jiuli.liping.controller;

import com.jiuli.liping.vo.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jiuli.liping.service.SupplierService;

import java.util.List;

/**
 * Author zyl
 * Date  2020-03-25
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    @RequestMapping(value = {"/list", ""}, method = RequestMethod.GET)
    public Object list() {
        List<Supplier> suppliers = supplierService.findAllList();
        return suppliers;
    }

    @RequestMapping(value = {"/get"}, method = RequestMethod.GET)
    public Object get(@RequestParam String id) {
        Supplier supplier = supplierService.get(id);
        return supplier;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public String insert(@RequestBody Supplier supplier) {
        if (supplierService.insert(supplier) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST)
    public String insertBatch(@RequestBody List<Supplier> suppliers) {
        if (supplierService.insertBatch(suppliers) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(@RequestBody Supplier supplier) {
        if (supplierService.update(supplier) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(@RequestBody Supplier supplier) {
        if (supplierService.delete(supplier) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

}
